<template>
	<view class="container">
		<view class="empty" v-if="book.length < 1">
			<image class="image" src="@/static/img/empty.png" mode="aspectFit"></image>
			<view class="emptyWord">暂无数据</view>
		</view>
		<view class="bookList" v-else>
			<view class="book" hover-class="hoverClass" v-for="item in book" :key="item.id" @click="detail(item)">
				<view class="info">
					<view class="name">{{ item.customer_name }}</view>
					<view class="time">预定周期：{{ item.start_date }} 至 {{ item.end_date }}</view>
				</view>
				<uni-icons type="right" size="16" color="#bbb"></uni-icons>
			</view>
		</view>
		<view class="addBtn" @click="addBook">
			<uni-icons type="plusempty" size="32" color="#fff"></uni-icons>
		</view>
	</view>
</template>

<script>
import api from '@/api/api';
export default {
	data() {
		return {
			id: null,
			room: {},
			book: []
		};
	},
	onLoad(e) {
		this.id = e.id;
	},
	onShow() {
		this.getRoomDetail();
		this.getBookList();
	},
	onPullDownRefresh() {
		this.getBookList();
	},
	methods: {
		detail(item) {
			uni.navigateTo({
				url: '/pages/details/book?sn=' + item.rent_sn
			});
		},
		addBook() {
			uni.navigateTo({
				url: '/pages/add/book?id=' + this.id
			});
		},
		getBookList() {
			uni.showLoading({
				title: '加载中...'
			});
			api.bookList({ room_id: this.id }).then((res) => {
				this.book = res.data.items;
				this.loading = false;
				uni.hideLoading();
				uni.stopPullDownRefresh();
			});
		},
		getRoomDetail() {
			api.roomDetail({ room_id: this.id }).then((res) => {
				this.room = res.data.info;
			});
		}
	}
};
</script>

<style lang="scss">
.container {
	padding: 20rpx;
	.book {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 20rpx;
		background: #fff;
		border-radius: 16rpx;
		margin-bottom: 20rpx;
		.name {
			font-size: 28rpx;
			font-weight: bold;
			margin-bottom: 10rpx;
		}
		.time {
			font-size: 26rpx;
		}
	}
}
</style>
